//
//  SLHomeAccountView.m
//  SoccerLottery
//
//  Created by chuanshuangzhang chuan shuang on 15/12/25.
//  Copyright © 2015年 chuanshuangzhang. All rights reserved.
//

#import "SLHomeAccountView.h"

@implementation SLHomeAccountView

- (id)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        _amountLabel = [self labelWithLocation:2];
        UIButton *chargeBtn = [[UIButton alloc]init];
        [chargeBtn setTitle:@"充值" forState:UIControlStateNormal];
        chargeBtn.frame = CGRectMake(0,0,frame.size.height * 1.077,frame.size.height*0.39);
        chargeBtn.center = CGPointMake(App_Frame_Width-15-chargeBtn.frame.size.width/2.0, frame.size.height/2.0);
        [chargeBtn applyActionStyle];
        [chargeBtn setBackgroundImage:[Utils createImageWithColor:RGBACOLOR(230, 51, 76, 1.0)] forState:UIControlStateNormal];
        [chargeBtn addTarget:self action:@selector(charge:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:chargeBtn];
        
        _loginBtn = [[UIButton alloc]init];
        [_loginBtn setTitle:@"会员登录" forState:UIControlStateNormal];
        [_loginBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
        _loginBtn.frame = CGRectMake(0,0,frame.size.height * 1.2,frame.size.height*0.39);
        _loginBtn.center = CGPointMake(frame.size.width/2.0, frame.size.height/2.0);
        [_loginBtn applyActionStyle];
        [_loginBtn setBackgroundImage:[Utils createImageWithColor:RGBACOLOR(236, 73,93, 1.0)] forState:UIControlStateNormal];
        [_loginBtn addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_loginBtn];
        
        _accountLabel = [self labelWithLocation:1];

    }
    return self;
}

- (IBAction)charge:(id)sender
{
    if(self.delegate && [self.delegate respondsToSelector:@selector(accountViewDidSelectCharge:)]){
        [self.delegate accountViewDidSelectCharge:self];
    }
}

- (IBAction)login:(id)sender
{
    if(self.delegate && [self.delegate respondsToSelector:@selector(accountViewDidSelectLogin:)]){
        [self.delegate accountViewDidSelectLogin:self];
    }
}
- (UILabel *)labelWithLocation:(NSInteger)location
{
    UILabel *label = [[UILabel alloc]init];
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:18];
    [label setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self addSubview:label];
    if(location == 1){
     [self addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
    }else {
     [self addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10]];
    }
    [self addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
    return label;
}
@end
